package leetcode.jianzhioffer;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-10-29 09:12
 **/
public class JianZhiOffer27 {

    /*public TreeNode mirrorTree(TreeNode root) {
        if (root == null) {
            return root;
        }
        Deque<TreeNode> deque = new LinkedList<>();
        deque.offer(root);
        //临时节点
        TreeNode temp = null;
        TreeNode temp2 = null;
        while (!deque.isEmpty()) {
            int size = deque.size();

            for (int i = 0; i < size; i++) {
                temp = deque.poll();
                temp2 = temp.left;
                temp.left = temp.right;
                temp.right = temp2;
                if (temp.left != null) {
                    deque.offer(temp.left);
                }
                if (temp.right != null) {
                    deque.offer(temp.right);
                }
            }
        }

        return root;
    }*/

    public TreeNode mirrorTree(TreeNode root) {
        if (root == null) {
            return root;
        }
        mirrorTree(root.left);
        mirrorTree(root.right);
        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;
        return root;
    }
}
